using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Net.Protocols
{
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using System.IO;
    using System.Net.Sockets;

    public class NetMessage
    {
        public Encoding Encoding { get; set; } = new UTF8Encoding(false);
        public object Head { get; set; }

        public Stream Body { get; set; }

        public T GetHeadValue<T>(string key)
        {
            var head = Head as JObject;
            return head == null ? default(T) : (head[key] == null ? default(T) : head[key].ToObject<T>());
        }
        public string GetHeadValueString(string key)
        {
            var head = Head as JObject;
            return head == null ? null : (head[key] == null ? null : head[key].ToString());
        }
        public int? GetHeadValueInt32(string key)
        {
            var head = Head as JObject;
            return head == null ? null : (head[key] == null ? null : head[key].ToObject<int?>());
        }
    }

}
